package com.longxi.tianjintianbao.ui.activity.rectification;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.widget.Button;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.Personnel;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.presenter.rectification.RectificationDetailAtPresenter;
import com.longxi.tianjintianbao.ui.view.rectification.IRectificationDetailAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class RectificationDetailActivity extends BaseActivity<IRectificationDetailAtView, RectificationDetailAtPresenter> implements IRectificationDetailAtView {
    @BindView(R.id.rvContent)
    RecyclerView mRvContent;
    @BindView(R.id.btnLogin)
    Button mBtnLogin;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_rectification_detail;
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter.setBar();
        mPresenter.initAdapter();
        mPresenter.getRectification();
    }

    @Override
    public void initListener() {
        super.initListener();
        mBtnLogin.setOnClickListener(v -> mPresenter.goFinshOrChange());
    }

    @Override
    protected RectificationDetailAtPresenter createPresenter() {
        return new RectificationDetailAtPresenter(this);
    }

    @Override
    public RecyclerView getRvContent() {
        return mRvContent;
    }

    @Override
    public Button getBtnLogin() {
        return mBtnLogin;
    }

    /**
     * 让 dialogfragment获取到父类的人员列表 这样才能进行增加
     * @return
     */
    public List<Personnel> getPersonnels(){
        return mPresenter.getPersonnels();
    }

    /**
     * 用户删除已选择的人
     * @param personnel
     * @return
     */
    public boolean deletePersonnels(Personnel personnel){
        return mPresenter.deletePersonnels(personnel);
    }

    /**
     * 品质整改完成
     * @param finishremark
     */
    public void saveRectificationState(String finishremark){



        if(mPresenter.personnels.size() == 1){
            MyUtils.showToast("请先选择指派人员");
            return;
        }

        mPresenter.saveRectificationState(finishremark);
    }

    @Override
    protected void onDestroy() {
        mPresenter.onDestroy();
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mPresenter.onActivityResult(requestCode, resultCode, data);
    }
}


